package com.forenow.demo.demo21;

/**  面试题
 *  throws 与 throw的区别
 *  throws 放在可能出现异常的方法后面
 *  throw 表示明确抛出一个异常
 */
public class Exceptiondemo2 {
    public int add(int a,int b)throws Exception {
        if (a<0||b<0) {
            Exception e=new Exception();
            throw e;
        }
        return a+b;
    }

    public static void main(String[] args) {
        Exceptiondemo2 demo2=new Exceptiondemo2();
        try {
            demo2.add(-1,-2);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
